﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ManagementSystem
{
    /// <summary>
    /// 查询教师信息窗体
    /// </summary>
    public partial class SelectTeacher : Form
    {
        private SystemServices services;
        public SelectTeacher()
        {
            InitializeComponent();
            services = new SystemServices();
        }

        /// <summary>
        /// 按工号查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonID_Click(object sender, EventArgs e)
        {
            //获取输入
            string ID = textBoxID.Text.Trim();
            if (string.IsNullOrEmpty(ID))
            {
                MessageBox.Show("工号不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            //异常处理
            try
            {
                // 获取查询信息
                var filteredt = services.SelecttID(ID).ToList();

                if (!filteredt.Any())
                {
                    MessageBox.Show("未找到匹配的教师信息", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                //显示查询结果窗体
                FormTeacher formTeacher1 = new FormTeacher(filteredt);
                formTeacher1.ShowDialog();


            }
            catch (Exception ex)
            {
                MessageBox.Show($"查询过程中发生错误: {ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        /// <summary>
        /// 按姓名查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonName_Click(object sender, EventArgs e)
        {
            //获取输入
            string Name = textBoxName.Text.Trim();
            if (string.IsNullOrEmpty(Name))
            {
                MessageBox.Show("姓名不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            //异常处理
            try
            {
                // 获取查询信息
                var filteredt = services.SelecttName(Name).ToList();

                if (!filteredt.Any())
                {
                    MessageBox.Show("未找到匹配的教师信息", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                //显示查询结果窗体
                FormTeacher2 formTeacher2 = new FormTeacher2(filteredt);
                formTeacher2.ShowDialog();


            }
            catch (Exception ex)
            {
                MessageBox.Show($"查询过程中发生错误: {ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        /// <summary>
        /// 按职称查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonTitle_Click(object sender, EventArgs e)
        {
            //获取输入
            string Title = textBoxTitle.Text.Trim();
            if (string.IsNullOrEmpty(Title))
            {
                MessageBox.Show("职称不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            //异常处理
            try
            {
                // 获取查询信息
                var filteredt = services.SelecttTitle(Title).ToList();

                if (!filteredt.Any())
                {
                    MessageBox.Show("未找到匹配的教师信息", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                //显示查询结果窗体
                FormTeacher3 formTeacher3 = new FormTeacher3(filteredt);
                formTeacher3.ShowDialog();


            }
            catch (Exception ex)
            {
                MessageBox.Show($"查询过程中发生错误: {ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void SelectTeacher_Load(object sender, EventArgs e)
        {

        }
    }
}
